/*     */ package com.qmsk.business.order.orderMain.controller;
/*     */ 
/*     */ import com.qmsk.business.manage.cust.dao.CustDAO;
/*     */ import com.qmsk.business.member.memberdepositbill.dao.MemberDepositBillDAO;
/*     */ import com.qmsk.business.order.orderDetail.dao.OrderDetailDao;
/*     */ import com.qmsk.business.order.orderMain.dao.OrderMainDao;
/*     */ import com.utils.basic.CDateTimeComm;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"orderMain"})
/*     */ public class OrderMainController
/*     */ {
/*  37 */   private static final Logger logger = Logger.getLogger(OrderMainController.class);
/*     */ 
/*     */   @Autowired
/*     */   private OrderMainDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private OrderDetailDao orderDetailDao;
/*     */ 
/*     */   @Autowired
/*     */   private CustDAO custDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositBillDAO memberDepositBillDAO;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  56 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  58 */       GsonEbRst gsonEbRst = null;
/*  59 */       String openId = RequestUtils.getString(request, "openId", null);
/*  60 */       if ((shopId.longValue() > 0L) && (StringUtils.isNotEmpty(openId))) {
/*  61 */         Long custId = null;
/*  62 */         if (StringUtils.isNotEmpty(openId)) {
/*  63 */           custId = this.custDao.getCustIdOfOpenId(openId, shopId);
/*     */         }
/*  65 */         if (custId.longValue() > 0L) {
/*  66 */           Map params = new HashMap();
/*  67 */           params.put("shopId", shopId);
/*  68 */           params.put("openId", openId);
/*  69 */           params.put("customerID", custId);
/*  70 */           gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*     */         }
/*     */       }
/*  73 */       if ((gsonEbRst != null) && 
/*  74 */         (!(gsonEbRst.isExistsData()))) {
/*  75 */         gsonEbRst = null;
/*     */       }
/*     */ 
/*  78 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  80 */       logger.error(e);
/*  81 */       ResponseUtils.setErrorMsgResponse(
/*  82 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/*  90 */       Map params = new HashMap();
/*  91 */       MapUtils.addToMap(params, "id", id);
/*  92 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params);
/*  93 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  95 */       logger.error(e);
/*  96 */       ResponseUtils.setErrorMsgResponse(
/*  97 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"insert/shopId/{shopId}/{openId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("openId") String openId)
/*     */   {
/*     */     try
/*     */     {
/* 115 */       int nResult = 0;
/* 116 */       Long id = null;
/* 117 */       Long custId = null;
/*     */ 
/* 119 */       boolean isExsitOrder = false;
/* 120 */       if (StringUtils.isNotEmpty(openId)) {
/* 121 */         custId = this.custDao.getCustIdOfOpenId(openId, shopId);
/*     */       }
/* 123 */       if (custId.longValue() > 0L) {
/* 124 */         id = this.dao.isExsitOrderMain(custId, openId, shopId);
/* 125 */         if (id.longValue() > 0L) {
/* 126 */           isExsitOrder = true;
/*     */         }
/*     */       }
/*     */ 
/* 130 */       String sData = RequestUtils.getStringOfData(request);
/* 131 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 132 */       if (!(isExsitOrder)) {
/* 133 */         if ((p != null) && (p.isExistsInsertRows())) {
/* 134 */           for (int i = 0; i < p.getListInsertRows().size(); ++i) {
/* 135 */             GsonHeadOneRow g = (GsonHeadOneRow)p.getListInsertRows().get(i);
/*     */ 
/* 138 */             if (custId.longValue() <= 0L) {
/* 139 */               ResponseUtils.setErrorMsgResponse("cust", response);
/* 140 */               return;
/*     */             }
/* 142 */             String sMaxBillNo = this.memberDepositBillDAO
/* 143 */               .getMaxBillNo(shopId);
/* 144 */             g.autoAddHeadData(
/* 145 */               new String[] { "customerID", "maker", 
/* 146 */               "makeTime", "money", "orderStatus", 
/* 147 */               "receiveID", "orderEndTime", 
/* 148 */               "orderMainNo" }, 
/* 149 */               new Object[] { 
/* 150 */               custId, 
/* 151 */               "wx", 
/* 152 */               new Date(), 
/* 153 */               Integer.valueOf(0), 
/* 154 */               Integer.valueOf(0), 
/* 155 */               custId, 
/* 157 */               CDateTimeComm.getAddDate(new Date(), 30), 
/* 158 */               sMaxBillNo });
/*     */           }
/*     */         }
/*     */ 
/* 162 */         nResult = this.dao.applyUpdates(p, "id");
/* 163 */         if ((p.isExistsInsertRows()) && (nResult > 0)) {
/* 164 */           GsonHeadOneRow r = (GsonHeadOneRow)p.getListInsertRows().get(0);
/* 165 */           id = ObjectComm.objectToLong(r.getValueOfName("id"));
/*     */         }
/*     */       }
/* 168 */       if ((nResult > 0) || (p == null) || (p.isExistsRows())) {
/* 169 */         ParserDataSetJson pgdsPrice = 
/* 170 */           ParserDataSetJson.fromString(RequestUtils.getString(request, 
/* 171 */           "detailData"));
/* 172 */         if (pgdsPrice != null) {
/* 173 */           if (pgdsPrice.isExistsInsertRows()) {
/* 174 */             for (int i = 0; i < pgdsPrice.getListInsertRows()
/* 175 */               .size(); )
/*     */             {
/* 176 */               GsonHeadOneRow r = 
/* 177 */                 (GsonHeadOneRow)pgdsPrice.getListInsertRows()
/* 177 */                 .get(i);
/* 178 */               if (id != null) {
/* 179 */                 r.autoAddHeadData("orderDtId", id);
/*     */               }
/* 181 */               Long goodsId = ObjectComm.objectToLong(r
/* 182 */                 .getValueOfName("goodsID"));
/* 183 */               if ((id.longValue() > 0L) && (goodsId.longValue() > 0L) && 
/* 185 */                 (this.orderDetailDao
/* 185 */                 .getIsOrderDetail(id, goodsId))) {
/* 186 */                 DbConnection.rollback();
/* 187 */                 ResponseUtils.setErrorMsgResponse(
/* 188 */                   "购物车已存在该商品，如要修改请去购物车操作", response);
/* 189 */                 return;
/*     */               }
/*     */ 
/* 192 */               if (r.getValueOfName("price") != null) {
/* 193 */                 Integer num = ObjectComm.objectToInteger(
/* 194 */                   r.getValueOfName("num"), Integer.valueOf(0));
/* 195 */                 Double price = ObjectComm.objectToDouble(
/* 196 */                   r.getValueOfName("price"), Integer.valueOf(0));
/* 197 */                 Double subtotal = Double.valueOf(num.intValue() * price.doubleValue());
/* 198 */                 if (subtotal.doubleValue() > 0.0D)
/* 199 */                   r.addHeadData("subtotal", subtotal);
/*     */               }
/* 175 */               ++i;
/*     */             }
/*     */ 
/*     */           }
/*     */ 
/* 204 */           nResult += this.orderDetailDao.applyUpdates(pgdsPrice);
/*     */         }
/*     */       }
/* 207 */       if (nResult > 0) {
/* 208 */         if (id.longValue() > 0L) {
/* 209 */           Double money = this.orderDetailDao.getMoney(id);
/* 210 */           if (money.doubleValue() > 0.0D) {
/* 211 */             this.dao.updateMoney(id, money);
/*     */           }
/*     */         }
/* 214 */         DbConnection.commit();
/* 215 */         String[] heads = { "Id" };
/* 216 */         Object[] datas = { id };
/* 217 */         ResponseUtils.toGsonEbRst(heads, datas, response);
/* 218 */         return; }
/* 219 */       DbConnection.rollback();
/* 220 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 221 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 222 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 225 */       logger.error(e);
/* 226 */       DbConnection.rollback();
/* 227 */       ResponseUtils.setErrorMsgResponse(
/* 228 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 229 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 295 */     String id = RequestUtils.getString(request, "mId", null);
/*     */     try {
/* 297 */       String[] strParams = id.split(",");
/* 298 */       int nResult = this.dao.deleteParams(strParams);
/* 299 */       GsonHeadOneRow g = new GsonHeadOneRow(
/* 300 */         new String[] { "OrderMainID" }, new Object[] { id });
/*     */ 
/* 302 */       nResult = nResult + this.orderDetailDao
/* 302 */         .deletePkGsonHeadOneRow(g, 
/* 302 */         "crm_orderdetail");
/* 303 */       if (nResult > 0)
/* 304 */         DbConnection.commit();
/*     */       else {
/* 306 */         DbConnection.rollback();
/*     */       }
/* 308 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 309 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 310 */         response);
/*     */     } catch (Exception e) {
/* 312 */       DbConnection.rollback();
/* 313 */       logger.error(e);
/* 314 */       ResponseUtils.setErrorMsgResponse(
/* 315 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 316 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.order.orderMain.controller.OrderMainController
 * JD-Core Version:    0.5.3
 */